import 'package:animation/components/input/normal_input.dart';
import 'package:animation/components/tabs/VerticalTabs.dart';
import 'package:animation/generated/l10n.dart';
import 'package:animation/pages/other/navchild/search_child.dart/bilibili_search.dart';
import 'package:animation/pages/other/navchild/search_child.dart/cyapi_search.dart';
import 'package:animation/pages/other/navchild/search_child.dart/nuno_search.dart';
import 'package:flutter/material.dart';

class SearchPage extends StatefulWidget {
  const SearchPage({super.key});

  @override
  State<SearchPage> createState() => _SearchPageState();
}

class _SearchPageState extends State<SearchPage> {
  TextEditingController controller = TextEditingController();
  bool change = false;
  List<Tabs> tabs = [
    Tabs(title: 'bilibili'),
    Tabs(title: '迟言'),
    Tabs(title: '诺诺子一'),
    Tabs(title: '诺诺子二'),
  ];

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(''),
        toolbarHeight: 0,
        elevation: 0,
        leading: null,
        backgroundColor: Theme.of(context).colorScheme.primaryContainer,
        surfaceTintColor: Theme.of(context).colorScheme.primaryContainer,
      ),
      body: Column(
        children: [
          _buildSearch(),
          Expanded(
            child: VerticalTabs(
              tabsWidth: 90,
              tabBackgroundColor:
                  Theme.of(context).colorScheme.primaryContainer,
              selectedTabTextStyle:
                  TextStyle(color: Theme.of(context).colorScheme.primary),
              indicatorColor: Theme.of(context).colorScheme.primary,
              unSelectedTabTextStyle: TextStyle(color: Colors.grey),
              indicatorSide: IndicatorSide.start,
              tabs: tabs,
              backgroundColor: Colors.transparent,
              contents: [
                BilibiliSearch(keyword: controller.text, change: change),
                CyapiSearch(keyword: controller.text, change: change),
                NunoSearch(keyword: controller.text, url: 1, change: change),
                NunoSearch(keyword: controller.text, url: 2, change: change),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildSearch() {
    return Container(
        padding: EdgeInsets.only(left: 10, right: 10, bottom: 2, top: 2),
        color: Theme.of(context).colorScheme.primaryContainer,
        child: Row(
          children: [
            Expanded(
              child: NormalInput(
                height: 33,
                controller: controller,
                title: S.of(context).a8,
                onSubmitted: (v) {
                  FocusScope.of(context).requestFocus(FocusNode());
                  setState(() {
                    change = !change;
                  });
                },
              ),
            ),
            IconButton(
                onPressed: () {
                  FocusScope.of(context).requestFocus(FocusNode());
                  setState(() {
                    change = !change;
                  });
                },
                icon: Icon(Icons.search))
          ],
        ));
  }
}
